<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('keystore列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            keystore名称：<input type="text" name="keystoreName"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:keystore:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:keystore:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:keystore:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:keystore:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:keystore:remove')}]];
    var prefix = ctx + "system/keystore";


    function jksDownload(url) {
        if (url) {
            window.location.href = url
        } else {
            $.modal.alertError("下载地址错误");
        }
    }


    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            sortName: "sort",
            modalName: "keystore",
            columns: [{
                checkbox: true
            },
                {
                    field: 'keystoreId',
                    title: 'keystore编号'
                },
                {
                    field: 'keystoreName',
                    title: 'keystore名称',
                    sortable: true
                },
                {
                    field: 'alias',
                    title: '别名',
                    sortable: true
                },
                {
                    field: 'c',
                    title: '详细信息',
                    sortable: false,
                    formatter: function (value, item, index) {
                        var cn = item.cn || 'unknown'
                        var ou = item.ou || 'unknown'
                        var o = item.o || 'unknown'
                        var l = item.l || 'unknown'
                        var st = item.st || 'unknown'
                        var c = item.c || 'unknown'

                        return `cn=${cn},ou=${ou},o=${o},l=${l},st=${st},c=${c}`
                    }
                },
                {
                    field: 'fileName',
                    title: 'keystore文件名',
                    sortable: false
                },
                {
                    field: 'remark',
                    title: '备注',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    field: 'sort',
                    title: '显示顺序',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.initial === 0) {
                            return [].join('');
                        }
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.keystoreId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.keystoreId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="jksDownload(\'' + row.fileUrl + '\')"><i class="fa fa-download   "></i>下载</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>